﻿// <copyright file="PuzzleSolutionShape.cs" company="ThorIndustry">Copyright (c) ThorIndustry. All rights reserved.</copyright>

using System.Collections.Generic;

public class PuzzleSolutionShape : IWorldVerticeProvider
{
    public PuzzleSolutionShape(PuzzleSolution puzzleSolution)
    {
        this.PuzzleSolution = puzzleSolution;
    }

    public PuzzleSolution PuzzleSolution
    {
        get;
        set;
    }

    public PuzzleShape[] SolutionShapes
    {
        get;
        set;
    }

    public UnityEngine.Vector3[] WorldVertices
    {
        get;
        set;
    }

    public void Initialize()
    {
        this.SolutionShapes = new PuzzleShape[this.PuzzleSolution.PolygonDefinitions.Length];

        int verticesCount = 0;
        for (int index = 0; index < this.PuzzleSolution.PolygonDefinitions.Length; ++index)
        {
            this.SolutionShapes[index] = new PuzzleShape(this.PuzzleSolution.PolygonDefinitions[index]);
            this.SolutionShapes[index].Initialize();

            verticesCount += this.SolutionShapes[index].WorldVertices.Length;
        }

        this.WorldVertices = new UnityEngine.Vector3[verticesCount];

        int shapeIndex = 0;
        int verticeIndex = 0;
        for (int index = 0; index < this.WorldVertices.Length; ++index)
        {
            if (this.SolutionShapes[shapeIndex].WorldVertices.Length <= verticeIndex)
            {
                shapeIndex++;
                verticeIndex = 0;
            }

            this.WorldVertices[index] = this.SolutionShapes[shapeIndex].WorldVertices[verticeIndex];
            verticeIndex++;
        }
    }
}
